package com.ukao.cashregister.dialog;


import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.ukao.cashregister.R;
import com.ukao.cashregister.base.BaseDialogFragment;
import com.ukao.cashregister.consts.SaveParamets;
import com.ukao.cashregister.eventbus.MembershipCardEvent;
import com.ukao.cashregister.utils.ImageUtils;
import com.ukao.cashregister.widget.StateButton;
import com.ukao.cashregister.widget.StateImageView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * 退出登录对话框
 */
public class QuitLoginDialogFragment extends BaseDialogFragment {

    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";
    @BindView(R.id.imgPath)
    ImageView imgPath;
    @BindView(R.id.name)
    TextView name;
    @BindView(R.id.phone)
    TextView phone;
    @BindView(R.id.quit_button)
    StateButton quitButton;
    Unbinder unbinder;
    @BindView(R.id.close_btn)
    StateImageView closeBtn;
    @BindView(R.id.title)
    TextView title;

    private String mParam1;
    private String mParam2;


    public static QuitLoginDialogFragment newInstance(String param1, String param2) {
        QuitLoginDialogFragment fragment = new QuitLoginDialogFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment_quit_login_dialog, container, false);
        unbinder = ButterKnife.bind(this, view);
        title.setText("退出当前账号");
        ImageUtils.loadImage(activity, SaveParamets.getHeadimgPath(activity), imgPath, R.drawable.login_head);
        name.setText(SaveParamets.getSaveUseName(activity));
        phone.setText(SaveParamets.getSaveUsePhone(activity));

        return view;
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }


    @OnClick({R.id.close_btn, R.id.quit_button})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.close_btn:
                dismiss();
                break;
            case R.id.quit_button:
                MembershipCardEvent.postNoData(MembershipCardEvent.Message.quit);
                dismiss();
                break;
        }
    }
}
